from django.contrib.staticfiles.storage import staticfiles_storage
from django.urls import reverse
from jinja2 import Environment, filters


def jinja2_environment(**options):
    env = Environment(**options)
    env.globals.update({
        'static': staticfiles_storage.url,
        'url': reverse,
    })
    return env


def title_gl(value):
    if len(value) > 25:
        value = value[:24] + "......"
    return value


def zz_gl(value):
    if len(value) > 5:
        value = value[:5] + "..."
    return value


def time_gl(value):
    value = str(value)[:19]
    return value


filters.FILTERS["title_gl"] = title_gl
filters.FILTERS["zz_gl"] = zz_gl
filters.FILTERS["time_gl"] = time_gl
